package uast.bpdex.actions.addInfoG;

import uast.bpdex.actions.addInfoG.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.util.regex.*;
import uast.bpdex.forms.addInfoG;
import uast.bpdex.BaseDatos.*;
import uast.bpdex.*;
import java.sql.SQLException;

public class addInfoGAction extends org.apache.struts.action.Action {

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String target = "failAddInfoG";
        String id = "06-11-011";    // id del proyecto en la base de datos
        String resumen;
        String logros;
        String fortaleza;
        String oportunidad;
        String debilidad;
        String amenaza;
        String indicadores;
        String resultFis;
        String resultFinan;
        String conclu;
        DataBase db;
        InfoGestion ig;

        // Si no se lleno el formulario se invoca al caso fallido
        if(form == null) return mapping.findForward(target);

        // Se obtienen los datos del formulario
        addInfoG form0 = (addInfoG)form;
        resumen = form0.getResumen();
        logros = form0.getLogros();
        fortaleza = form0.getFortaleza();
        oportunidad = form0.getOportunidad();
        debilidad = form0.getDebilidad();
        amenaza = form0.getAmenaza();
        indicadores = form0.getIndicadores();
        resultFis = form0.getResultFis();
        resultFinan = form0.getResultFinan();
        conclu = form0.getConclu();
        db = new DataBase();

        // Se agrega el informe de gestion a la base de datos y se invoca al caso exitoso
        try {

            ig = new InfoGestion(id, resumen, logros, fortaleza, oportunidad, debilidad, amenaza, indicadores, resultFis, resultFinan, conclu);
            db.agregarInfoGestion(ig);

            target = "succAddInfoG";
        // Si no se logra, se invoca el caso fallido
        } catch(Exception ex0) {
           return mapping.findForward(target);
        }

        return mapping.findForward(target);
    }

}